package Lotr.game.Entity;

import Lotr.game.GameManager;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

public class Tower {

    protected int ID;
    protected double radius;
    protected double rate;
    protected int width, height;
    protected int posX, posY;
    protected boolean chosen, placed;
    protected GameManager gameManager;

    public void update() {
        Point mousePos = gameManager.getMousePosition();
        if (chosen) {
            if (mousePos != null) {
                posX = mousePos.x - width / 2;
                posY = mousePos.y - height / 2;
            }
        }

    }

    public void chosen() {
        if(placed){
            return;
        }
        if (chosen) {
            abort();
            return;
        }
        chosen = true;
    }

    public void abort() {
        chosen = false;
    }

    public void render(Graphics g) {
        if (chosen) {
            g.setColor(Color.RED);
            g.fillOval(posX, posY, width, height);
        } else if (placed) {
            g.setColor(Color.RED);
            g.fillOval(posX, posY, width, height);
        }
    }

    public void place() {
        if(placed){
            return;
        }
        chosen = false;
        Point mousePos = gameManager.getMousePosition();
        if (mousePos != null) {
            posX = mousePos.x - width / 2;
            posY = mousePos.y - height / 2;
        }
        //TODO: Gültigkeit der Position prüfen
        placed = true;
    }
}
